package com.example.bgmachine.bgmachine.orders;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.goods.HomepageGridRightMenuAdapter;
import com.example.bgmachine.bgmachine.goods.HomepageGridRightMenuItemData;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class OrderFragment extends Fragment {
    private Context mContext = null;

    private GridView order_infor_item_gridvew = null;

    public OrderContentAdapter mOrderContentAdapter = null;
    public List<OrderContentData> mOrderContentData = null;
    public OrderFragment() {

    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @NonNull Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.order_fragment_layout, container, false);
        mContext =view.getContext();
        order_infor_item_gridvew =  view.findViewById(R.id.order_infor_item_gridvew);
        mOrderContentData = new LinkedList<OrderContentData>();
        mOrderContentAdapter = new OrderContentAdapter(mContext,(LinkedList<OrderContentData>) mOrderContentData);
        if (order_infor_item_gridvew != null) {
            order_infor_item_gridvew.setAdapter(mOrderContentAdapter);
        }
        return view;
    }
    public void  clearItem(){
        if (mOrderContentAdapter != null) {
            mOrderContentAdapter.clear();

            mOrderContentAdapter.notifyDataSetChanged();

        }
    }
    public void  addItem(OrderContentData orderContentData){
        if (mOrderContentAdapter != null) {
            mOrderContentAdapter.add(orderContentData);

            mOrderContentAdapter.notifyDataSetChanged();

        }
    }

    public int getItemLength(){
        if (mOrderContentAdapter != null) {
            return mOrderContentAdapter.getCount();
        }else {
            return 0;
        }
    }

    public OrderContentData  getItemInfor(int indexs){
        if (mOrderContentAdapter != null) {
            return (OrderContentData) mOrderContentAdapter.getItem(indexs);
        }else {
            return null;
        }
    }
    public void removeOrderContentData(OrderContentData rderContentData) {

        if (mOrderContentAdapter != null) {
            mOrderContentAdapter.remove(rderContentData);
            mOrderContentAdapter.notifyDataSetChanged();

        }
    }
}
